package com.company.nuwa.mybatis.generator.plugins;

import org.apache.commons.text.CaseUtils;
import org.mybatis.generator.api.GeneratedJavaFile;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.JavaVisibility;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import org.mybatis.generator.config.Context;
import org.mybatis.generator.config.PropertyRegistry;
import org.mybatis.generator.internal.util.StringUtility;

import java.sql.Types;
import java.text.MessageFormat;
import java.util.List;

/**
 * <p>API</p>
 *
 * @author lili
 * @version 1.0: ApiExtPlugin
 * @date 2023/9/16 17:16
 */
public class ApiExtPlugin {

    public static GeneratedJavaFile addRequestFile(IntrospectedTable introspectedTable,
                                                   Context context,
                                                   String targetProject) {
        String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
        StringBuilder builder = new StringBuilder();
        FullyQualifiedJavaType mapperType = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3JavaMapperType());
        TopLevelClass requestClass = new TopLevelClass(builder.delete(0, builder.length())
            .append(mapperType.getPackageName().replace(".mapper", "").replace("domain", "request"))
            .append(".").append(domainObjectName).append("AddRequest").toString());
        requestClass.setVisibility(JavaVisibility.PUBLIC);
        context.getCommentGenerator().addJavaFileComment(requestClass);
        FullyQualifiedJavaType domainType = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
        //requestClass.addImportedType(domainType);
        requestClass.addSuperInterface(new FullyQualifiedJavaType("Serializable"));
        //添加domain的import
        requestClass.addImportedType("java.io.Serializable");
        requestClass.addImportedType("lombok.Data");
        requestClass.addImportedType("lombok.experimental.Accessors");
        requestClass.addImportedType("com.fasterxml.jackson.annotation.JsonIgnoreProperties");
        requestClass.addImportedType("com.fasterxml.jackson.annotation.JsonFormat");
        requestClass.addImportedType("jakarta.validation.constraints.NotNull");
        requestClass.addImportedType("javax.annotation.Generated");
        //添加domain的注解
        requestClass.addAnnotation("@Data");
        requestClass.addAnnotation("@Accessors(chain = true)");
        requestClass.addAnnotation("@JsonIgnoreProperties(ignoreUnknown = true)");
        //@Slf4j
        FullyQualifiedJavaType slf4j = new FullyQualifiedJavaType("lombok.extern.slf4j.Slf4j");
        requestClass.addAnnotation("@Slf4j");
        requestClass.addImportedType(slf4j);
        requestClass.addJavaDocLine("/**");
        String remarks = introspectedTable.getRemarks();
        if (StringUtility.stringHasValue(remarks)) {
            String[] remarkLines = remarks.split(System.getProperty("line.separator"));
            for (String remarkLine : remarkLines) {
                requestClass.addJavaDocLine(" * <p>" + remarkLine + "</p>");
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append(" * @author ").append(System.getProperties().getProperty("user.name"));
        requestClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * ").append("@version 1.0:")
            .append(introspectedTable.getFullyQualifiedTable().getDomainObjectName())
            .append("Request").append(".java");
        requestClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * @date ");
        sb.append(ApiExtPluginUtils.getDateString());
        requestClass.addJavaDocLine(sb.toString());
        requestClass.addJavaDocLine(" */");
        //生成字段
        List<IntrospectedColumn> columns = introspectedTable.getAllColumns();
        for (IntrospectedColumn introspectedColumn : columns) {
            String columnName = CaseUtils.toCamelCase(introspectedColumn.getActualColumnName(),
                false, '_');
            Field field = new Field(columnName, introspectedColumn.getFullyQualifiedJavaType());
            field.addJavaDocLine("/**");
            String fieldRemarks = introspectedColumn.getRemarks();
            if (StringUtility.stringHasValue(fieldRemarks)) {
                String[] remarkLines = fieldRemarks.split(System.getProperty("line.separator"));
                for (String remarkLine : remarkLines) {
                    field.addJavaDocLine(" * " + remarkLine);
                }
            }
            field.addJavaDocLine(" */");
            if (introspectedColumn.getJdbcType() == Types.TIME) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (introspectedColumn.getJdbcType() == Types.TIMESTAMP) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (introspectedColumn.getJdbcType() == Types.DATE) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (introspectedColumn.getJdbcType() == Types.DATE) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (!introspectedColumn.isNullable()) {
                field.addAnnotation(MessageFormat.format("@NotNull(message = \"{0}不能为空\")",
                    introspectedColumn.getRemarks()));
            }
            field.addAnnotation("@Generated(\"org.mybatis.generator.api.MyBatisGenerator\")");
            field.setVisibility(JavaVisibility.PRIVATE);
            requestClass.addField(field);
        }

        GeneratedJavaFile generatedJavaFile = new GeneratedJavaFile(requestClass, targetProject,
                context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
                context.getJavaFormatter());
        return generatedJavaFile;
    }

    public static GeneratedJavaFile updateRequestFile(IntrospectedTable introspectedTable,
                                                      Context context,
                                                      String targetProject) {
        String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
        StringBuilder builder = new StringBuilder();
        FullyQualifiedJavaType mapperType = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3JavaMapperType());
        TopLevelClass requestClass = new TopLevelClass(builder.delete(0, builder.length())
            .append(mapperType.getPackageName().replace(".mapper", "").replace("domain", "request"))
            .append(".").append(domainObjectName).append("UpdateRequest").toString());
        requestClass.setVisibility(JavaVisibility.PUBLIC);
        context.getCommentGenerator().addJavaFileComment(requestClass);
        FullyQualifiedJavaType domainType = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
        //requestClass.addImportedType(domainType);
        requestClass.addSuperInterface(new FullyQualifiedJavaType("Serializable"));
        //添加domain的import
        requestClass.addImportedType("java.io.Serializable");
        requestClass.addImportedType("lombok.Data");
        requestClass.addImportedType("lombok.experimental.Accessors");
        requestClass.addImportedType("com.fasterxml.jackson.annotation.JsonIgnoreProperties");
        requestClass.addImportedType("com.fasterxml.jackson.annotation.JsonFormat");
        requestClass.addImportedType("jakarta.validation.constraints.NotNull");
        requestClass.addImportedType("javax.annotation.Generated");
        //添加domain的注解
        requestClass.addAnnotation("@Data");
        requestClass.addAnnotation("@Accessors(chain = true)");
        requestClass.addAnnotation("@JsonIgnoreProperties(ignoreUnknown = true)");
        //@Slf4j
        FullyQualifiedJavaType slf4j = new FullyQualifiedJavaType("lombok.extern.slf4j.Slf4j");
        requestClass.addAnnotation("@Slf4j");
        requestClass.addImportedType(slf4j);
        requestClass.addJavaDocLine("/**");
        String remarks = introspectedTable.getRemarks();
        if (StringUtility.stringHasValue(remarks)) {
            String[] remarkLines = remarks.split(System.getProperty("line.separator"));
            for (String remarkLine : remarkLines) {
                requestClass.addJavaDocLine(" * <p>" + remarkLine + "</p>");
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append(" * @author ").append(System.getProperties().getProperty("user.name"));
        requestClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * ").append("@version 1.0:")
            .append(introspectedTable.getFullyQualifiedTable().getDomainObjectName())
            .append("Request").append(".java");
        requestClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * @date ");
        sb.append(ApiExtPluginUtils.getDateString());
        requestClass.addJavaDocLine(sb.toString());
        requestClass.addJavaDocLine(" */");
        //生成字段
        List<IntrospectedColumn> columns = introspectedTable.getAllColumns();
        for (IntrospectedColumn introspectedColumn : columns) {
            String columnName = CaseUtils.toCamelCase(introspectedColumn.getActualColumnName(),
                false, '_');

            Field field = new Field(columnName, introspectedColumn.getFullyQualifiedJavaType());
            field.addJavaDocLine("/**");
            String fieldRemarks = introspectedColumn.getRemarks();
            if (StringUtility.stringHasValue(fieldRemarks)) {
                String[] remarkLines = fieldRemarks.split(System.getProperty("line.separator"));
                for (String remarkLine : remarkLines) {
                    field.addJavaDocLine(" * " + remarkLine);
                }
            }
            field.addJavaDocLine(" */");
            if (introspectedColumn.getJdbcType() == Types.TIME) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (introspectedColumn.getJdbcType() == Types.TIMESTAMP) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (introspectedColumn.getJdbcType() == Types.DATE) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }

            if (!introspectedColumn.isNullable()) {
                field.addAnnotation(MessageFormat.format("@NotNull(message = \"{0}不能为空\")",
                    introspectedColumn.getRemarks()));
            }
            field.addAnnotation("@Generated(\"org.mybatis.generator.api.MyBatisGenerator\")");
            field.setVisibility(JavaVisibility.PRIVATE);
            requestClass.addField(field);
        }

        GeneratedJavaFile generatedJavaFile = new GeneratedJavaFile(requestClass,
            targetProject,
            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
            context.getJavaFormatter());
        return generatedJavaFile;
    }

    public static GeneratedJavaFile dtoFile(IntrospectedTable introspectedTable, Context context,
                                            String targetProject) {
        String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
        StringBuilder builder = new StringBuilder();
        FullyQualifiedJavaType mapperType = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3JavaMapperType());
        TopLevelClass requestClass = new TopLevelClass(builder.delete(0, builder.length())
            .append(mapperType.getPackageName().replace(".mapper", "").replace("domain", "dto"))
            .append(".").append(domainObjectName).append("DTO").toString());
        requestClass.setVisibility(JavaVisibility.PUBLIC);
        context.getCommentGenerator().addJavaFileComment(requestClass);
        FullyQualifiedJavaType domainType = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
        //requestClass.addImportedType(domainType);
        requestClass.addSuperInterface(new FullyQualifiedJavaType("Serializable"));
        //添加domain的import
        requestClass.addImportedType("java.io.Serializable");
        requestClass.addImportedType("lombok.Data");
        requestClass.addImportedType("lombok.experimental.Accessors");
        requestClass.addImportedType("com.fasterxml.jackson.annotation.JsonIgnoreProperties");
        requestClass.addImportedType("com.fasterxml.jackson.annotation.JsonFormat");
        requestClass.addImportedType("jakarta.validation.constraints.NotNull");
        requestClass.addImportedType("javax.annotation.Generated");
        //添加domain的注解
        requestClass.addAnnotation("@Data");
        requestClass.addAnnotation("@Accessors(chain = true)");
        requestClass.addAnnotation("@JsonIgnoreProperties(ignoreUnknown = true)");
        //@Slf4j
        FullyQualifiedJavaType slf4j = new FullyQualifiedJavaType("lombok.extern.slf4j.Slf4j");
        requestClass.addAnnotation("@Slf4j");
        requestClass.addImportedType(slf4j);
        requestClass.addJavaDocLine("/**");
        String remarks = introspectedTable.getRemarks();
        if (StringUtility.stringHasValue(remarks)) {
            String[] remarkLines = remarks.split(System.getProperty("line.separator"));
            for (String remarkLine : remarkLines) {
                requestClass.addJavaDocLine(" * <p>" + remarkLine + "</p>");
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append(" * @author ").append(System.getProperties().getProperty("user.name"));
        requestClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * ").append("@version 1.0:")
            .append(introspectedTable.getFullyQualifiedTable().getDomainObjectName()).append("DTO")
            .append(".java");
        requestClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * @date ");
        sb.append(ApiExtPluginUtils.getDateString());
        requestClass.addJavaDocLine(sb.toString());
        requestClass.addJavaDocLine(" */");
        //生成字段
        List<IntrospectedColumn> columns = introspectedTable.getAllColumns();
        for (IntrospectedColumn introspectedColumn : columns) {
            String columnName = CaseUtils.toCamelCase(introspectedColumn.getActualColumnName(),
                false, '_');

            Field field = new Field(columnName, introspectedColumn.getFullyQualifiedJavaType());
            field.addJavaDocLine("/**");
            String fieldRemarks = introspectedColumn.getRemarks();
            if (StringUtility.stringHasValue(fieldRemarks)) {
                String[] remarkLines = fieldRemarks.split(System.getProperty("line.separator"));
                for (String remarkLine : remarkLines) {
                    field.addJavaDocLine(" * " + remarkLine);
                }
            }
            field.addJavaDocLine(" */");
            if (introspectedColumn.getJdbcType() == Types.TIME) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (introspectedColumn.getJdbcType() == Types.TIMESTAMP) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (introspectedColumn.getJdbcType() == Types.DATE) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            field.setVisibility(JavaVisibility.PRIVATE);
//            if (!introspectedColumn.isNullable()) {
//                field.addAnnotation(MessageFormat.format("@NotNull(message = \"{0}不能为空\")",
//                    introspectedColumn.getRemarks()));
//            }
            field.addAnnotation("@Generated(\"org.mybatis.generator.api.MyBatisGenerator\")");
            requestClass.addField(field);
        }
        //
        GeneratedJavaFile generatedJavaFile = new GeneratedJavaFile(requestClass,
                targetProject,
            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
            context.getJavaFormatter());
        return generatedJavaFile;
    }

    public static GeneratedJavaFile selectByIdsFile(IntrospectedTable introspectedTable,
                                                    Context context,
                                                    String targetProject) {
        String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
        StringBuilder builder = new StringBuilder();
        FullyQualifiedJavaType mapperType = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3JavaMapperType());
        TopLevelClass requestClass = new TopLevelClass(builder.delete(0, builder.length())
            .append(mapperType.getPackageName().replace(".mapper", "").replace("domain", "request"))
            .append(".").append(domainObjectName).append("SelectByIdsRequest").toString());
        requestClass.setVisibility(JavaVisibility.PUBLIC);
        context.getCommentGenerator().addJavaFileComment(requestClass);
        requestClass.addSuperInterface(new FullyQualifiedJavaType("Serializable"));
        //添加domain的import
        requestClass.addImportedType("java.io.Serializable");
        requestClass.addImportedType("lombok.Data");
        requestClass.addImportedType("lombok.experimental.Accessors");
        requestClass.addImportedType("com.fasterxml.jackson.annotation.JsonIgnoreProperties");
        requestClass.addImportedType("com.fasterxml.jackson.annotation.JsonFormat");
        requestClass.addImportedType("jakarta.validation.constraints.NotNull");
        requestClass.addImportedType("java.util.List");
        requestClass.addImportedType("javax.annotation.Generated");
        //添加domain的注解
        requestClass.addAnnotation("@Data");
        requestClass.addAnnotation("@Accessors(chain = true)");
        requestClass.addAnnotation("@JsonIgnoreProperties(ignoreUnknown = true)");
        //@Slf4j
        FullyQualifiedJavaType slf4j = new FullyQualifiedJavaType("lombok.extern.slf4j.Slf4j");
        requestClass.addAnnotation("@Slf4j");
        requestClass.addImportedType(slf4j);
        requestClass.addJavaDocLine("/**");
        String remarks = introspectedTable.getRemarks();
        if (StringUtility.stringHasValue(remarks)) {
            String[] remarkLines = remarks.split(System.getProperty("line.separator"));
            for (String remarkLine : remarkLines) {
                requestClass.addJavaDocLine(" * <p>" + remarkLine + "</p>");
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append(" * @author ").append(System.getProperties().getProperty("user.name"));
        requestClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * ").append("@version 1.0:")
            .append(introspectedTable.getFullyQualifiedTable().getDomainObjectName())
            .append("SelectByIdsRequest").append(".java");
        requestClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * @date ");
        sb.append(ApiExtPluginUtils.getDateString());
        requestClass.addJavaDocLine(sb.toString());
        requestClass.addJavaDocLine(" */");
        //生成字段
        Field field = new Field("ids", new FullyQualifiedJavaType("List<Long>"));
        field.addAnnotation("@Generated(\"org.mybatis.generator.api.MyBatisGenerator\")");
        field.addAnnotation(MessageFormat.format("@NotNull(message = \"{0}不能为空\")", "ids"));
        field.setVisibility(JavaVisibility.PRIVATE);
        requestClass.addField(field);
        GeneratedJavaFile generatedJavaFile = new GeneratedJavaFile(requestClass,
                targetProject,
            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
            context.getJavaFormatter());
        return generatedJavaFile;
    }

    public static GeneratedJavaFile selectPageFile(IntrospectedTable introspectedTable,
                                                   Context context,
                                                   String targetProject) {
        String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
        StringBuilder builder = new StringBuilder();
        FullyQualifiedJavaType mapperType = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3JavaMapperType());
        TopLevelClass requestClass = new TopLevelClass(builder.delete(0, builder.length())
            .append(mapperType.getPackageName().replace(".mapper", "").replace("domain", "request"))
            .append(".").append(domainObjectName).append("SelectPageRequest").toString());
        requestClass.setVisibility(JavaVisibility.PUBLIC);
        context.getCommentGenerator().addJavaFileComment(requestClass);
        requestClass.setSuperClass(new FullyQualifiedJavaType("BasePage"));
        //添加domain的import
        requestClass.addImportedType("com.company.nuwa.common.domain.BasePage");
        requestClass.addImportedType("java.io.Serializable");
        requestClass.addImportedType("lombok.Data");
        requestClass.addImportedType("lombok.experimental.Accessors");
        requestClass.addImportedType("com.fasterxml.jackson.annotation.JsonIgnoreProperties");
        requestClass.addImportedType("com.fasterxml.jackson.annotation.JsonFormat");
        requestClass.addImportedType("jakarta.validation.constraints.NotNull");
        requestClass.addImportedType("javax.annotation.Generated");
        //添加domain的注解
        requestClass.addAnnotation("@Data");
        requestClass.addAnnotation("@Accessors(chain = true)");
        requestClass.addAnnotation("@JsonIgnoreProperties(ignoreUnknown = true)");
        //@Slf4j
        FullyQualifiedJavaType slf4j = new FullyQualifiedJavaType("lombok.extern.slf4j.Slf4j");
        requestClass.addAnnotation("@Slf4j");
        requestClass.addImportedType(slf4j);
        requestClass.addJavaDocLine("/**");
        String remarks = introspectedTable.getRemarks();
        if (StringUtility.stringHasValue(remarks)) {
            String[] remarkLines = remarks.split(System.getProperty("line.separator"));
            for (String remarkLine : remarkLines) {
                requestClass.addJavaDocLine(" * <p>" + remarkLine + "</p>");
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append(" * @author ").append(System.getProperties().getProperty("user.name"));
        requestClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * ").append("@version 1.0:")
            .append(introspectedTable.getFullyQualifiedTable().getDomainObjectName())
            .append("Request").append(".java");
        requestClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * @date ");
        sb.append(ApiExtPluginUtils.getDateString());
        requestClass.addJavaDocLine(sb.toString());
        requestClass.addJavaDocLine(" */");
        //生成字段
        List<IntrospectedColumn> columns = introspectedTable.getAllColumns();
        for (IntrospectedColumn introspectedColumn : columns) {
            String columnName = CaseUtils.toCamelCase(introspectedColumn.getActualColumnName(),
                false, '_');

            Field field = new Field(columnName, introspectedColumn.getFullyQualifiedJavaType());
            field.addJavaDocLine("/**");
            String fieldRemarks = introspectedColumn.getRemarks();
            if (StringUtility.stringHasValue(fieldRemarks)) {
                String[] remarkLines = fieldRemarks.split(System.getProperty("line.separator"));
                for (String remarkLine : remarkLines) {
                    field.addJavaDocLine(" * " + remarkLine);
                }
            }
            field.addJavaDocLine(" */");
            if (introspectedColumn.getJdbcType() == Types.TIME) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (introspectedColumn.getJdbcType() == Types.TIMESTAMP) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (introspectedColumn.getJdbcType() == Types.DATE) {
                field.addAnnotation(
                    "@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
            }
            if (!introspectedColumn.isNullable()) {
                field.addAnnotation(MessageFormat.format("@NotNull(message = \"{0}不能为空\")",
                    introspectedColumn.getRemarks()));
            }
            field.addAnnotation("@Generated(\"org.mybatis.generator.api.MyBatisGenerator\")");
            field.setVisibility(JavaVisibility.PRIVATE);
            requestClass.addField(field);
        }

        GeneratedJavaFile generatedJavaFile = new GeneratedJavaFile(requestClass,
            targetProject,
            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
            context.getJavaFormatter());
        return generatedJavaFile;
    }

}
